<template>
  <div class="index">
    <!-- 首页header -->
    <header>
      <div class="logo">
        <img src="../assets/image/logo_white.png" alt="" />
      </div>
      <input type="text" v-model="searchTxt" placeholder="HUAWEI Mate 50" />
      <div class="chat"><icon name="chat-o" /></div>
      <router-link :to="{ name: 'User' }">
        <div class="login"><icon name="contact"></icon></div>
      </router-link>
    </header>
    <div class="main">
      <div class="bg">
        <!-- 轮播图 -->
        <div class="indexSwipe">
          <swipe class="my-swipe" :autoplay="3000" indicator-color="#bbb">
            <swipe-item
              ><img src="../assets/image/swipe/swipe1.jpg" alt="" @click="toDetail(63)"
            /></swipe-item>
            <swipe-item
              ><img src="../assets/image/swipe/swipe2.jpg" alt="" @click="toDetail(79)"
            /></swipe-item>
            <swipe-item
              ><img src="../assets/image/swipe/swipe3.jpg" alt="" @click="toDetail(69)"
            /></swipe-item>
            <swipe-item
              ><img src="../assets/image/swipe/swipe4.jpg" alt="" @click="toDetail(68)"
            /></swipe-item>
          </swipe>
        </div>

        <!-- 导航 -->
        <div class="indexGrid">
          <li>
            <div class="content" @click="toCategory(17)">
              <img src="../assets/image/indexGrid/indexGrid1.jpg" alt="" />
              <p>智慧办公</p>
            </div>
          </li>
          <li>
            <div class="content" @click="toCategory(18)">
              <img src="../assets/image/indexGrid/indexGrid2.jpg" alt="" />
              <p>智能家居</p>
            </div>
          </li>
          <li>
            <div class="content" @click="toCategory(5)">
              <img src="../assets/image/indexGrid/indexGrid3.gif" alt="" />
              <p>华为手机</p>
            </div>
          </li>
          <li>
            <div class="content" @click="toCategory(19)">
              <img src="../assets/image/indexGrid/indexGrid4.jpg" alt="" />
              <p>影音娱乐</p>
            </div>
          </li>
          <li>
            <div class="content" @click="toCategory(6)">
              <img src="../assets/image/indexGrid/indexGrid5.jpg" alt="" />
              <p>运动健康</p>
            </div>
          </li>
          <li>
            <div class="content" @click="toCategory(21)">
              <img src="../assets/image/indexGrid/indexGrid6.jpg" alt="" />
              <p>鸿蒙智连</p>
            </div>
          </li>
          <li>
            <div class="content" @click="toCategory(28)">
              <img src="../assets/image/indexGrid/indexGrid7.jpg" alt="" />
              <p>华为智选</p>
            </div>
          </li>
          <li>
            <div class="content" @click="toCategory(22)">
              <img src="../assets/image/indexGrid/indexGrid8.jpg" alt="" />
              <p>AITO汽车</p>
            </div>
          </li>
          <li>
            <div class="content">
              <img src="../assets/image/indexGrid/indexGrid9.jpg" alt="" />
              <p>秒杀</p>
            </div>
          </li>
          <li>
            <div class="content">
              <img src="../assets/image/indexGrid/indexGrid10.jpg" alt="" />
              <p>直播</p>
            </div>
          </li>
        </div>
      </div>

      <MayLike></MayLike>
    </div>
  </div>
</template>

<script setup>
import { useRouter } from "vue-router";
import { ref, provide, inject } from "vue";
import { Swipe, SwipeItem, Icon } from "vant";
//引入猜你喜欢组件
import MayLike from "../components/MayLike.vue";

const router = useRouter();

// inject("aaa", "");
// console.log(aaa);

const searchTxt = ref("");
// const allGoods = ref([]);
provide("searchTxt", searchTxt);

// 跳转列表页
const toCategory = (id) => {
  router.push({
    name: "Category",
    query: { c_id: id },
  });
};


//跳转详情页
const toDetail = (id) => {
  router.push({
    name: "Detail",
    query: {
      id,
    },
  });
};
</script>

<style scoped lang="scss">
.index {
  .main {
    margin-top: 58px;
  }
}
header {
  display: flex;
  z-index: 1;
  position: fixed;
  display: flex;
  flex-wrap: nowrap;
  justify-content: space-between;
  height: 58px;
  width: 100%;
  background-color: #f84d4e;
  padding-left: 18px;
  .logo {
    // float: left;
    padding-top: 16px;
  }
  input {
    background-color: #fcb8b8;
    height: 40px;
    width: 45vw;
    border-radius: 18px;
    border: none;
    margin: 10px 13px 0;
    text-indent: 1.5rem;
    // line-height: 40px;
    color: #555;
    font-size: 16px;
  }
  .chat {
    // float: left;
    // width: 60px;
    font-size: 24px;
    color: #fff;
    line-height: 58px;
    margin-right: 5px;
  }
  .login {
    // float: right;
    font-size: 22px;
    color: #fff;
    margin-right: 15px;
    line-height: 58px;
  }
}
.bg {
  width: 100%;
  background: linear-gradient(to bottom, #f84d4e 10%, #f1f3f5 100%);
  .indexSwipe {
    width: 90%;
    margin: 0 auto;
    border-radius: 1rem;
    overflow: hidden;
    .my-swipe .van-swipe-item {
      color: #fff;
      font-size: 20px;
      line-height: 150px;
      text-align: center;
      // background-color: #39a9ed;
    }
    .van-swipe-item {
      width: 90vw;
      height: 38.3vw;
      img {
        width: 100%;
        height: auto;
      }
    }
  }
  .indexGrid {
    width: 90%;
    margin: 10px auto;
    display: grid;
    place-items: center center;
    // grid-template-rows: 20% 20% 20% 20% 20%;
    grid-template-columns: 20% 20% 20% 20% 20%;
    li {
      .content {
        margin: 0 auto;
        text-align: center;
        width: 70px;
        height: 90px;
        p {
          margin-top: 4px;
          text-align: center;
          font-size: 12px;
        }
        img {
          height: 48px;
          width: 48px;
        }
      }
    }
  }
}
</style>
